package org.gavin.controller;

import com.alibaba.fastjson2.JSONObject;
import org.gavin.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * PubMsgTask
 *
 * @author grl
 * @date 2025/2/11
 */
@RestController
public class PubMsgTask {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;


    @GetMapping(value = "/sendMsg")
    public R<JSONObject> pubMsg(@RequestParam(value = "msg")String msg,@RequestParam(value = "channel")String channel) {
        System.out.println("redisTemplate正在发送消息 "+ channel+ "  " + msg);
        redisTemplate.convertAndSend(channel, msg);
        return R.ok();
    }
}
